package admin

import (
	"gin_demo/internal/consts"
	"gin_demo/utility"

	"github.com/gin-gonic/gin"
)

var Admin = new(cAdmin)

type cAdmin struct{}

//@Summary  后台用户数据添加接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body admin.AdminReq{} true "添加请求参数"
//@Router  /backend/admin/add  [post]
//@version 1.0
func (a cAdmin) Create(ctx *gin.Context) {
	req := AdminReq{}
	if err := ctx.ShouldBindJSON(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Create(ctx, req)
	}
}

//@Summary  后台用户数据列表接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param Limit query int true "一次性最大页数"
//@Param Page query int true "当前页数"
//@Router  /backend/admin/list  [get]
//@version 1.0
func (a cAdmin) List(ctx *gin.Context) {
	List(ctx)
}

//@Summary  后台用户数据删除接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body admin.SoftDeleteReq{} true "删除请求参数"
//@Router  /backend/admin/del  [delete]
//@version 1.0
func (a cAdmin) Delete(ctx *gin.Context) {
	req := SoftDeleteReq{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, "删除失败")
	} else {
		Delete(ctx, req)
	}

}

//@Summary  后台用户密码修改接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body admin.UpdateMyPasswordReq{} true "更新请求参数"
//@Router  /backend/admin/update  [put]
//@version 1.0
func (a cAdmin) Update(ctx *gin.Context) {
	req := UpdateMyPasswordReq{}
	if err := ctx.ShouldBind(&req); err != nil {
		consts.App.Log.Error(err.Error())
		utility.Fail(ctx, "用户密码修改失败，请提交正确的参数")
	} else {
		Update(ctx, req)
	}
}
